package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.CommonRecyclerViewAdapter;
import com.jucai.pppeiyouclient.bean.OrderBean;
import com.jucai.pppeiyouclient.comm.CommonRequestNetData;
import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.view.dialog.EndOrderDialog;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Kuky on 2017-04-21.
 */

public class RunningOrderAdapter extends CommonRecyclerViewAdapter<OrderBean> {
    private static final String TAG = "RunningOrderAdapter : ";

    public RunningOrderAdapter(Context context, List<OrderBean> data) {
        super(context, data);
    }

    @Override
    public void bindHolder(final CommonHolder holder, final OrderBean orderBean) {
        holder.setImage(R.id.order_user_img, orderBean.getMember_avatar(), 60, 60);
        holder.setText(R.id.order_number, "订单编号：" + orderBean.getTorder_ordersn());

        if(!TextUtils.isEmpty(orderBean.getMember_realname())) {
            holder.setText(R.id.order_user_name, orderBean.getMember_realname());
        }else {
            // String temp = orderBean.getMember_realname();
            //temp = temp.substring(0, 3) + "****" + temp.substring(7, 11);
            holder.setText(R.id.order_user_name, orderBean.getMember_phone());
        }

        holder.setText(R.id.order_user_info, orderBean.getMember_sexual() + " " + orderBean.getMember_age() + "岁");
        holder.setText(R.id.order_start_time, "" + orderBean.getTorder_start_time());
        holder.setText(R.id.order_start_location, "" + orderBean.getTorder_start_point());
        holder.setGone(R.id.order_state);
        holder.setGone(R.id.order_state_str);
        holder.setGone(R.id.order_create_time);
        if (TextUtils.equals(orderBean.getTorder_status(),"3")) {
            holder.setVisible(R.id.order_end);
            holder.setOnclickListener(R.id.order_end, new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    final EndOrderDialog endOrderDialog = new EndOrderDialog(mContext);
                    endOrderDialog.setOnclickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            if (view.getId() == R.id.end_sure) {
                                HashMap<String, String> param = new HashMap<>();
                                param.put("service", "Conductor_Order.closeservice");
                                param.put("id", orderBean.getTorder_id());

                                CommonRequestNetData.getJsonStringDataByEncrpt(mContext, param, new CommonRequestNetData.ResultCallBack() {
                                    @Override
                                    public void parseJsonString(String str) {
                                        LogUtils.e(TAG + "str = " + str);
                                        holder.setGone(R.id.order_end);
                                    }

                                    @Override
                                    public void onError(String str) {
                                        holder.setVisible(R.id.order_end);
                                    }
                                });
                                endOrderDialog.dismiss();
                            }
                        }
                    });
                    endOrderDialog.show();
                }
            });
        }
    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_order_layout;
    }

}
